/*
Copyright 2010  Murali Devi (profdevi@gmail.com)

This file is part of ComineGL Project.

ComineGL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

ComineGL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with ComineGL.  If not, see <http://www.gnu.org/licenses/>.

This code uses the irrlicht and irrklang libraries.  Please read
the libraries copyrights at 

	irrlicht library:  http://irrlicht.sourceforge.net
	irrklang library:  http://www.ambiera.com/irrklang

*/



//v2.1 copyright Murali Devi 20101103W10
#ifndef MFile_h
#define MFile_h

///////////////////////////////////////////////////////
#ifdef WIN32
#undef UNICODE
#include <windows.h>
#else
#include "MStdLib.h"
#endif //WIN32

//////////////////////////////////////////////////////
#include "MIReader.h"
#include "MIWriter.h"

//******************************************************
//**  MFileOutput class for binary output
//******************************************************
class MFileOutput:public MIWriter
	{
	/////////////////////////////////////////////
	#ifdef WIN32
	HANDLE mFile;										// Handle to a Windows Handle	
	#else	// WIN32
	MStdFileHandle mFile;										// StdInput File
	#endif	// WIN32

	//////////////////////////////////////////////
	void ClearObject(void);

	//////////////////////////////////////////////
	public:
	MFileOutput(void);
	MFileOutput(const char *filename,bool append=false);
	~MFileOutput(void);
	bool Create(const char *filename,bool append=false);
	bool Destroy(void);
	bool OnWrite(const void *buffer,int length);		// Callback Handler for MIWriter
	int Tell(void);										// =Current position

	////////////////////////////////////////////////
	#ifdef WIN32
	HANDLE GetHandle(void);
	#else
	MStdFileHandle GetHandle(void);
	#endif //WIN32
	};


//******************************************************
//**  MFileInput class for binary input
//******************************************************
class MFileInput:public MIReader
	{
	///////////////////////////////////////////////
	#ifdef WIN32
	HANDLE mFile;
	#else // WIN32
	MStdFileHandle mFile;
	#endif //WIN32

	//////////////////////////////////////////////
	void ClearObject(void);

	//////////////////////////////////////////////
	public:
	MFileInput(void);
	MFileInput(const char *filename);
	~MFileInput(void);
	bool Create(const char *filename);
	bool Destroy(void);
	bool OnRead(void *block,int size);						// Callback Handler for MIReader
	int ReadToBuffer(void *buffer,int size);
	bool Seek(int offset,int relative=0);					// relative=0(beginning) 1(current) 2(end)
	int Tell(void);											// =Current position

	////////////////////////////////////////////////
	#ifdef WIN32
	HANDLE GetHandle(void);
	#else
	MStdFileHandle GetHandle(void);
	#endif //WIN32
	};

#endif // MFile_h
